﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Technoera.Common.Interop.OleDb
{
    public abstract class ExportMappingBase : IExportMapping
    {
        public ExportMappingBase(string targetColumnName, DataTypeDefinition targetColumnDataType)
        {
            TargetColumnName = targetColumnName;
            TargetColumnDataType = targetColumnDataType;
        }
        
        #region IExportMapping Members

        private string _targetColumnName;
        public virtual string TargetColumnName
        {
            get
            {
                if (_targetColumnName == null)
                    _targetColumnName = string.Empty;

                return _targetColumnName;
            }
            set
            {
                _targetColumnName = value;
            }
        }

        public virtual DataTypeDefinition TargetColumnDataType { get; set; }

        public abstract object GetPropertyValue(object instance);

        public virtual string GetSqlDataTypeName()
        {
            System.Data.SqlClient.SqlParameter sqlParam = new System.Data.SqlClient.SqlParameter();
            sqlParam.DbType = TargetColumnDataType.DataType;
            return sqlParam.SqlDbType.ToString();
        }

        #endregion
    }
}
